<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script type="text/javascript">
var n1=prompt("Please key in a random number.","e.g.123");
var n2=prompt("Please key in a random number.","e.g.123");
var result=n1*n2;
alert(result);
</script>
</head>
</html>
prompt()
is a dialogue box that user can key in values, and it will close until the user submit or cancel.
Basing on the rule, we can separate the user behavior into steps, like:
input: prompt(default value or an example)
→ operate → output: alert(data)
For example, to create a simple calculator...
var n1=prompt("Please key in a random number." , "7");
var n2=prompt("Please key in a random number." , "7");
var result=n1*n2;
alert(result);
=> The result is 49.
Feel free to comment and share your ideas below to learn together!
If you guys find this article helpful, please kindly do the writer a favor — LIKE this article.